import { ApiProperty } from "@nestjs/swagger";
import { Transform } from "class-transformer";
import { IsInt, IsOptional, IsPositive, Min } from "class-validator";

export class PageDto {
    /**
     * 当前页码
     */
    @Transform(v => +v.value)
    @IsInt({ message: "当前页必须为整数" })
    @IsPositive() // 必须是正数
    @Min(1, { message: "当前页不能小于 1" })
    @IsOptional()
    @ApiProperty({
        description: "当前页码",
        type: Number,
        minimum: 1,
        default: 1,
        required: false
    })
    current: number = 1;

    /**
     * 每页大小
     */
    @Transform(v => +v.value)
    @IsInt({ message: "每页大小必须为整数" })
    @IsPositive() // 必须是正数
    @Min(1, { message: "每页大小不能小于 1" })
    @IsOptional()
    @ApiProperty({
        description: "每页大小",
        type: Number,
        minimum: 1,
        default: 10,
        required: false
    })
    size: number = 10;
}
